********************************************************************************
** LOAD DATA
********************************************************************************

use "flanders_data.dta", clear

label drop _all

********************************************************************************
** SECOND DIFFERENCES (PVDA)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for PVDA
* ------------------------------------------------------------------------------

ologit seats_pvda i.party_pvda##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_pvda' with a full three-way interaction
* between party preference for PVDA, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_pvda) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_pvda',
* by party preference (PVDA or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-PVDA supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Pvda")
* Predicted probability of "less seats" for citizens, 2023 survey, PVDA supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-PVDA supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Pvda")
* Predicted probability of "less seats" for politicians, 2023 survey, PVDA supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-PVDA supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Pvda")
* Predicted probability of "less seats" for citizens, 2024 survey, PVDA supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-PVDA supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Pvda")
* Predicted probability of "less seats" for politicians, 2024 survey, PVDA supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-PVDA supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Pvda")
* Predicted probability of "same as now" for citizens, 2023 survey, PVDA supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-PVDA supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Pvda")
* Predicted probability of "same as now" for politicians, 2023 survey, PVDA supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-PVDA supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Pvda")
* Predicted probability of "same as now" for citizens, 2024 survey, PVDA supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-PVDA supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Pvda")
* Predicted probability of "same as now" for politicians, 2024 survey, PVDA supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-PVDA supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Pvda")
* Predicted probability of "more seats" for citizens, 2023 survey, PVDA supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-PVDA supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Pvda")
* Predicted probability of "more seats" for politicians, 2023 survey, PVDA supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-PVDA supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Pvda")
* Predicted probability of "more seats" for citizens, 2024 survey, PVDA supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-PVDA supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Pvda")
* Predicted probability of "more seats" for politicians, 2024 survey, PVDA supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring PVDA
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring PVDA for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Pvda_C_S23")
* Difference in predicted probabilities of "less seats" between PVDA supporters and others
* among citizens in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Pvda_C_S24")
* Difference in predicted probabilities of "less seats" between PVDA supporters and others
* among citizens in 2024 survey, showing the marginal effect of PVDA preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Pvda_P_S23")
* Difference in predicted probabilities of "less seats" between PVDA supporters and others
* among politicians in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Pvda_P_S24")
* Difference in predicted probabilities of "less seats" between PVDA supporters and others
* among politicians in 2024 survey, showing the marginal effect of PVDA preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Pvda_C_S23")
* Difference in predicted probabilities of "same as now" between PVDA supporters and others
* among citizens in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Pvda_C_S24")
* Difference in predicted probabilities of "same as now" between PVDA supporters and others
* among citizens in 2024 survey, showing the marginal effect of PVDA preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Pvda_P_S23")
* Difference in predicted probabilities of "same as now" between PVDA supporters and others
* among politicians in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Pvda_P_S24")
* Difference in predicted probabilities of "same as now" between PVDA supporters and others
* among politicians in 2024 survey, showing the marginal effect of PVDA preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Pvda_C_S23")
* Difference in predicted probabilities of "more seats" between PVDA supporters and others
* among citizens in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Pvda_C_S24")
* Difference in predicted probabilities of "more seats" between PVDA supporters and others
* among citizens in 2024 survey, showing the marginal effect of PVDA preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Pvda_P_S23")
* Difference in predicted probabilities of "more seats" between PVDA supporters and others
* among politicians in 2023 survey, showing the marginal effect of PVDA preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Pvda_P_S24")
* Difference in predicted probabilities of "more seats" between PVDA supporters and others
* among politicians in 2024 survey, showing the marginal effect of PVDA preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Pvda_S23")
* Tests whether the difference in the effect of PVDA preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Pvda_S24")
* Tests whether the difference in the effect of PVDA preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Pvda_S23")
* Tests whether the difference in the effect of PVDA preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Pvda_S24")
* Tests whether the difference in the effect of PVDA preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Pvda_S23")
* Tests whether the difference in the effect of PVDA preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Pvda_S24")
* Tests whether the difference in the effect of PVDA preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of PVDA preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Pvda")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Pvda")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Pvda")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Pvda) and Tests of 2nd and 3rd Differences")


********************************************************************************
** SECOND DIFFERENCES (GROEN)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for GROEN
* ------------------------------------------------------------------------------

ologit seats_groen i.party_groen##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_groen' with a full three-way interaction
* between party preference for GROEN, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_groen) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_groen',
* by party preference (GROEN or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-GROEN supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Groen")
* Predicted probability of "less seats" for citizens, 2023 survey, GROEN supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-GROEN supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Groen")
* Predicted probability of "less seats" for politicians, 2023 survey, GROEN supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-GROEN supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Groen")
* Predicted probability of "less seats" for citizens, 2024 survey, GROEN supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-GROEN supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Groen")
* Predicted probability of "less seats" for politicians, 2024 survey, GROEN supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-GROEN supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Groen")
* Predicted probability of "same as now" for citizens, 2023 survey, GROEN supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-GROEN supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Groen")
* Predicted probability of "same as now" for politicians, 2023 survey, GROEN supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-GROEN supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Groen")
* Predicted probability of "same as now" for citizens, 2024 survey, GROEN supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-GROEN supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Groen")
* Predicted probability of "same as now" for politicians, 2024 survey, GROEN supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-GROEN supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Groen")
* Predicted probability of "more seats" for citizens, 2023 survey, GROEN supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-GROEN supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Groen")
* Predicted probability of "more seats" for politicians, 2023 survey, GROEN supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-GROEN supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Groen")
* Predicted probability of "more seats" for citizens, 2024 survey, GROEN supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-GROEN supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Groen")
* Predicted probability of "more seats" for politicians, 2024 survey, GROEN supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring GROEN
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring GROEN for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Groen_C_S23")
* Difference in predicted probabilities of "less seats" between GROEN supporters and others
* among citizens in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Groen_C_S24")
* Difference in predicted probabilities of "less seats" between GROEN supporters and others
* among citizens in 2024 survey, showing the marginal effect of GROEN preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Groen_P_S23")
* Difference in predicted probabilities of "less seats" between GROEN supporters and others
* among politicians in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Groen_P_S24")
* Difference in predicted probabilities of "less seats" between GROEN supporters and others
* among politicians in 2024 survey, showing the marginal effect of GROEN preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Groen_C_S23")
* Difference in predicted probabilities of "same as now" between GROEN supporters and others
* among citizens in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Groen_C_S24")
* Difference in predicted probabilities of "same as now" between GROEN supporters and others
* among citizens in 2024 survey, showing the marginal effect of GROEN preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Groen_P_S23")
* Difference in predicted probabilities of "same as now" between GROEN supporters and others
* among politicians in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Groen_P_S24")
* Difference in predicted probabilities of "same as now" between GROEN supporters and others
* among politicians in 2024 survey, showing the marginal effect of GROEN preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Groen_C_S23")
* Difference in predicted probabilities of "more seats" between GROEN supporters and others
* among citizens in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Groen_C_S24")
* Difference in predicted probabilities of "more seats" between GROEN supporters and others
* among citizens in 2024 survey, showing the marginal effect of GROEN preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Groen_P_S23")
* Difference in predicted probabilities of "more seats" between GROEN supporters and others
* among politicians in 2023 survey, showing the marginal effect of GROEN preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Groen_P_S24")
* Difference in predicted probabilities of "more seats" between GROEN supporters and others
* among politicians in 2024 survey, showing the marginal effect of GROEN preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Groen_S23")
* Tests whether the difference in the effect of GROEN preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Groen_S24")
* Tests whether the difference in the effect of GROEN preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Groen_S23")
* Tests whether the difference in the effect of GROEN preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Groen_S24")
* Tests whether the difference in the effect of GROEN preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Groen_S23")
* Tests whether the difference in the effect of GROEN preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Groen_S24")
* Tests whether the difference in the effect of GROEN preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of GROEN preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Groen")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Groen")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Groen")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Groen) and Tests of 2nd and 3rd Differences")


********************************************************************************
** SECOND DIFFERENCES (VOORUIT)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for VOORUIT
* ------------------------------------------------------------------------------

ologit seats_vooruit i.party_vooruit##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_vooruit' with a full three-way interaction
* between party preference for VOORUIT, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_vooruit) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_vooruit',
* by party preference (VOORUIT or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-VOORUIT supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Vooruit")
* Predicted probability of "less seats" for citizens, 2023 survey, VOORUIT supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-VOORUIT supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Vooruit")
* Predicted probability of "less seats" for politicians, 2023 survey, VOORUIT supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-VOORUIT supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Vooruit")
* Predicted probability of "less seats" for citizens, 2024 survey, VOORUIT supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-VOORUIT supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Vooruit")
* Predicted probability of "less seats" for politicians, 2024 survey, VOORUIT supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-VOORUIT supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Vooruit")
* Predicted probability of "same as now" for citizens, 2023 survey, VOORUIT supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-VOORUIT supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Vooruit")
* Predicted probability of "same as now" for politicians, 2023 survey, VOORUIT supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-VOORUIT supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Vooruit")
* Predicted probability of "same as now" for citizens, 2024 survey, VOORUIT supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-VOORUIT supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Vooruit")
* Predicted probability of "same as now" for politicians, 2024 survey, VOORUIT supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-VOORUIT supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Vooruit")
* Predicted probability of "more seats" for citizens, 2023 survey, VOORUIT supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-VOORUIT supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Vooruit")
* Predicted probability of "more seats" for politicians, 2023 survey, VOORUIT supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-VOORUIT supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Vooruit")
* Predicted probability of "more seats" for citizens, 2024 survey, VOORUIT supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-VOORUIT supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Vooruit")
* Predicted probability of "more seats" for politicians, 2024 survey, VOORUIT supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring VOORUIT
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring VOORUIT for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Vooruit_C_S23")
* Difference in predicted probabilities of "less seats" between VOORUIT supporters and others
* among citizens in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Vooruit_C_S24")
* Difference in predicted probabilities of "less seats" between VOORUIT supporters and others
* among citizens in 2024 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Vooruit_P_S23")
* Difference in predicted probabilities of "less seats" between VOORUIT supporters and others
* among politicians in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Vooruit_P_S24")
* Difference in predicted probabilities of "less seats" between VOORUIT supporters and others
* among politicians in 2024 survey, showing the marginal effect of VOORUIT preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Vooruit_C_S23")
* Difference in predicted probabilities of "same as now" between VOORUIT supporters and others
* among citizens in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Vooruit_C_S24")
* Difference in predicted probabilities of "same as now" between VOORUIT supporters and others
* among citizens in 2024 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Vooruit_P_S23")
* Difference in predicted probabilities of "same as now" between VOORUIT supporters and others
* among politicians in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Vooruit_P_S24")
* Difference in predicted probabilities of "same as now" between VOORUIT supporters and others
* among politicians in 2024 survey, showing the marginal effect of VOORUIT preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Vooruit_C_S23")
* Difference in predicted probabilities of "more seats" between VOORUIT supporters and others
* among citizens in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Vooruit_C_S24")
* Difference in predicted probabilities of "more seats" between VOORUIT supporters and others
* among citizens in 2024 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Vooruit_P_S23")
* Difference in predicted probabilities of "more seats" between VOORUIT supporters and others
* among politicians in 2023 survey, showing the marginal effect of VOORUIT preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Vooruit_P_S24")
* Difference in predicted probabilities of "more seats" between VOORUIT supporters and others
* among politicians in 2024 survey, showing the marginal effect of VOORUIT preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Vooruit_S23")
* Tests whether the difference in the effect of VOORUIT preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Vooruit_S24")
* Tests whether the difference in the effect of VOORUIT preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Vooruit_S23")
* Tests whether the difference in the effect of VOORUIT preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Vooruit_S24")
* Tests whether the difference in the effect of VOORUIT preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Vooruit_S23")
* Tests whether the difference in the effect of VOORUIT preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Vooruit_S24")
* Tests whether the difference in the effect of VOORUIT preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of VOORUIT preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Vooruit")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Vooruit")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Vooruit")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Vooruit) and Tests of 2nd and 3rd Differences")


********************************************************************************
** SECOND DIFFERENCES (CDV)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for CDV
* ------------------------------------------------------------------------------

ologit seats_cdv i.party_cdv##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_cdv' with a full three-way interaction
* between party preference for CDV, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_cdv) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_cdv',
* by party preference (CDV or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-CDV supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Cdv")
* Predicted probability of "less seats" for citizens, 2023 survey, CDV supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-CDV supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Cdv")
* Predicted probability of "less seats" for politicians, 2023 survey, CDV supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-CDV supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Cdv")
* Predicted probability of "less seats" for citizens, 2024 survey, CDV supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-CDV supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Cdv")
* Predicted probability of "less seats" for politicians, 2024 survey, CDV supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-CDV supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Cdv")
* Predicted probability of "same as now" for citizens, 2023 survey, CDV supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-CDV supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Cdv")
* Predicted probability of "same as now" for politicians, 2023 survey, CDV supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-CDV supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Cdv")
* Predicted probability of "same as now" for citizens, 2024 survey, CDV supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-CDV supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Cdv")
* Predicted probability of "same as now" for politicians, 2024 survey, CDV supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-CDV supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Cdv")
* Predicted probability of "more seats" for citizens, 2023 survey, CDV supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-CDV supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Cdv")
* Predicted probability of "more seats" for politicians, 2023 survey, CDV supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-CDV supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Cdv")
* Predicted probability of "more seats" for citizens, 2024 survey, CDV supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-CDV supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Cdv")
* Predicted probability of "more seats" for politicians, 2024 survey, CDV supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring CDV
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring CDV for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Cdv_C_S23")
* Difference in predicted probabilities of "less seats" between CDV supporters and others
* among citizens in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Cdv_C_S24")
* Difference in predicted probabilities of "less seats" between CDV supporters and others
* among citizens in 2024 survey, showing the marginal effect of CDV preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Cdv_P_S23")
* Difference in predicted probabilities of "less seats" between CDV supporters and others
* among politicians in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Cdv_P_S24")
* Difference in predicted probabilities of "less seats" between CDV supporters and others
* among politicians in 2024 survey, showing the marginal effect of CDV preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Cdv_C_S23")
* Difference in predicted probabilities of "same as now" between CDV supporters and others
* among citizens in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Cdv_C_S24")
* Difference in predicted probabilities of "same as now" between CDV supporters and others
* among citizens in 2024 survey, showing the marginal effect of CDV preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Cdv_P_S23")
* Difference in predicted probabilities of "same as now" between CDV supporters and others
* among politicians in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Cdv_P_S24")
* Difference in predicted probabilities of "same as now" between CDV supporters and others
* among politicians in 2024 survey, showing the marginal effect of CDV preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Cdv_C_S23")
* Difference in predicted probabilities of "more seats" between CDV supporters and others
* among citizens in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Cdv_C_S24")
* Difference in predicted probabilities of "more seats" between CDV supporters and others
* among citizens in 2024 survey, showing the marginal effect of CDV preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Cdv_P_S23")
* Difference in predicted probabilities of "more seats" between CDV supporters and others
* among politicians in 2023 survey, showing the marginal effect of CDV preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Cdv_P_S24")
* Difference in predicted probabilities of "more seats" between CDV supporters and others
* among politicians in 2024 survey, showing the marginal effect of CDV preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Cdv_S23")
* Tests whether the difference in the effect of CDV preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Cdv_S24")
* Tests whether the difference in the effect of CDV preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Cdv_S23")
* Tests whether the difference in the effect of CDV preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Cdv_S24")
* Tests whether the difference in the effect of CDV preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Cdv_S23")
* Tests whether the difference in the effect of CDV preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Cdv_S24")
* Tests whether the difference in the effect of CDV preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of CDV preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Cdv")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Cdv")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Cdv")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Cdv) and Tests of 2nd and 3rd Differences")

********************************************************************************
** SECOND DIFFERENCES (OVLD)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for OVLD
* ------------------------------------------------------------------------------

ologit seats_ovld i.party_ovld##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_ovld' with a full three-way interaction
* between party preference for OVLD, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_ovld) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_ovld',
* by party preference (OVLD or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-OVLD supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Ovld")
* Predicted probability of "less seats" for citizens, 2023 survey, OVLD supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-OVLD supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Ovld")
* Predicted probability of "less seats" for politicians, 2023 survey, OVLD supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-OVLD supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Ovld")
* Predicted probability of "less seats" for citizens, 2024 survey, OVLD supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-OVLD supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Ovld")
* Predicted probability of "less seats" for politicians, 2024 survey, OVLD supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-OVLD supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Ovld")
* Predicted probability of "same as now" for citizens, 2023 survey, OVLD supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-OVLD supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Ovld")
* Predicted probability of "same as now" for politicians, 2023 survey, OVLD supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-OVLD supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Ovld")
* Predicted probability of "same as now" for citizens, 2024 survey, OVLD supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-OVLD supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Ovld")
* Predicted probability of "same as now" for politicians, 2024 survey, OVLD supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-OVLD supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Ovld")
* Predicted probability of "more seats" for citizens, 2023 survey, OVLD supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-OVLD supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Ovld")
* Predicted probability of "more seats" for politicians, 2023 survey, OVLD supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-OVLD supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Ovld")
* Predicted probability of "more seats" for citizens, 2024 survey, OVLD supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-OVLD supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Ovld")
* Predicted probability of "more seats" for politicians, 2024 survey, OVLD supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring OVLD
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring OVLD for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Ovld_C_S23")
* Difference in predicted probabilities of "less seats" between OVLD supporters and others
* among citizens in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Ovld_C_S24")
* Difference in predicted probabilities of "less seats" between OVLD supporters and others
* among citizens in 2024 survey, showing the marginal effect of OVLD preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Ovld_P_S23")
* Difference in predicted probabilities of "less seats" between OVLD supporters and others
* among politicians in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Ovld_P_S24")
* Difference in predicted probabilities of "less seats" between OVLD supporters and others
* among politicians in 2024 survey, showing the marginal effect of OVLD preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Ovld_C_S23")
* Difference in predicted probabilities of "same as now" between OVLD supporters and others
* among citizens in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Ovld_C_S24")
* Difference in predicted probabilities of "same as now" between OVLD supporters and others
* among citizens in 2024 survey, showing the marginal effect of OVLD preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Ovld_P_S23")
* Difference in predicted probabilities of "same as now" between OVLD supporters and others
* among politicians in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Ovld_P_S24")
* Difference in predicted probabilities of "same as now" between OVLD supporters and others
* among politicians in 2024 survey, showing the marginal effect of OVLD preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Ovld_C_S23")
* Difference in predicted probabilities of "more seats" between OVLD supporters and others
* among citizens in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Ovld_C_S24")
* Difference in predicted probabilities of "more seats" between OVLD supporters and others
* among citizens in 2024 survey, showing the marginal effect of OVLD preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Ovld_P_S23")
* Difference in predicted probabilities of "more seats" between OVLD supporters and others
* among politicians in 2023 survey, showing the marginal effect of OVLD preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Ovld_P_S24")
* Difference in predicted probabilities of "more seats" between OVLD supporters and others
* among politicians in 2024 survey, showing the marginal effect of OVLD preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Ovld_S23")
* Tests whether the difference in the effect of OVLD preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Ovld_S24")
* Tests whether the difference in the effect of OVLD preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Ovld_S23")
* Tests whether the difference in the effect of OVLD preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Ovld_S24")
* Tests whether the difference in the effect of OVLD preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Ovld_S23")
* Tests whether the difference in the effect of OVLD preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Ovld_S24")
* Tests whether the difference in the effect of OVLD preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of OVLD preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Ovld")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Ovld")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Ovld")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Ovld) and Tests of 2nd and 3rd Differences")


********************************************************************************
** SECOND DIFFERENCES (NVA)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for NVA
* ------------------------------------------------------------------------------

ologit seats_nva i.party_nva##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_nva' with a full three-way interaction
* between party preference for NVA, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_nva) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_nva',
* by party preference (NVA or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-NVA supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Nva")
* Predicted probability of "less seats" for citizens, 2023 survey, NVA supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-NVA supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Nva")
* Predicted probability of "less seats" for politicians, 2023 survey, NVA supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-NVA supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Nva")
* Predicted probability of "less seats" for citizens, 2024 survey, NVA supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-NVA supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Nva")
* Predicted probability of "less seats" for politicians, 2024 survey, NVA supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-NVA supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Nva")
* Predicted probability of "same as now" for citizens, 2023 survey, NVA supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-NVA supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Nva")
* Predicted probability of "same as now" for politicians, 2023 survey, NVA supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-NVA supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Nva")
* Predicted probability of "same as now" for citizens, 2024 survey, NVA supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-NVA supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Nva")
* Predicted probability of "same as now" for politicians, 2024 survey, NVA supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-NVA supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Nva")
* Predicted probability of "more seats" for citizens, 2023 survey, NVA supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-NVA supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Nva")
* Predicted probability of "more seats" for politicians, 2023 survey, NVA supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-NVA supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Nva")
* Predicted probability of "more seats" for citizens, 2024 survey, NVA supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-NVA supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Nva")
* Predicted probability of "more seats" for politicians, 2024 survey, NVA supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring NVA
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring NVA for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Nva_C_S23")
* Difference in predicted probabilities of "less seats" between NVA supporters and others
* among citizens in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Nva_C_S24")
* Difference in predicted probabilities of "less seats" between NVA supporters and others
* among citizens in 2024 survey, showing the marginal effect of NVA preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Nva_P_S23")
* Difference in predicted probabilities of "less seats" between NVA supporters and others
* among politicians in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Nva_P_S24")
* Difference in predicted probabilities of "less seats" between NVA supporters and others
* among politicians in 2024 survey, showing the marginal effect of NVA preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Nva_C_S23")
* Difference in predicted probabilities of "same as now" between NVA supporters and others
* among citizens in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Nva_C_S24")
* Difference in predicted probabilities of "same as now" between NVA supporters and others
* among citizens in 2024 survey, showing the marginal effect of NVA preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Nva_P_S23")
* Difference in predicted probabilities of "same as now" between NVA supporters and others
* among politicians in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Nva_P_S24")
* Difference in predicted probabilities of "same as now" between NVA supporters and others
* among politicians in 2024 survey, showing the marginal effect of NVA preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Nva_C_S23")
* Difference in predicted probabilities of "more seats" between NVA supporters and others
* among citizens in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Nva_C_S24")
* Difference in predicted probabilities of "more seats" between NVA supporters and others
* among citizens in 2024 survey, showing the marginal effect of NVA preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Nva_P_S23")
* Difference in predicted probabilities of "more seats" between NVA supporters and others
* among politicians in 2023 survey, showing the marginal effect of NVA preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Nva_P_S24")
* Difference in predicted probabilities of "more seats" between NVA supporters and others
* among politicians in 2024 survey, showing the marginal effect of NVA preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Nva_S23")
* Tests whether the difference in the effect of NVA preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Nva_S24")
* Tests whether the difference in the effect of NVA preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Nva_S23")
* Tests whether the difference in the effect of NVA preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Nva_S24")
* Tests whether the difference in the effect of NVA preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Nva_S23")
* Tests whether the difference in the effect of NVA preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Nva_S24")
* Tests whether the difference in the effect of NVA preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of NVA preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Nva")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Nva")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Nva")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Nva) and Tests of 2nd and 3rd Differences")


********************************************************************************
** SECOND DIFFERENCES (VB)
********************************************************************************

* ------------------------------------------------------------------------------
* STEP 1: Ordered Logit Model — 3-Way Interaction for VB
* ------------------------------------------------------------------------------

ologit seats_vb i.party_vb##i.type##i.survey i.sex age
* Estimate an ordered logit model predicting 'seats_vb' with a full three-way interaction
* between party preference for VB, actor type (citizen/politician), and survey wave.
* Controls include sex and age.
* This allows the effect of party preference to differ by type and survey wave.

* ------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* ------------------------------------------------------------------------------

margins, over(party_vb) at(type=(1 2) survey=(1 2)) post
* Calculate predicted probabilities for each level of 'seats_vb',
* by party preference (VB or not), for all combinations of type and survey wave.
* The 'post' option saves these results for mlincom analysis.

mlincom, clear
* Clear any previous linear combinations.

* ------------------------------------------------------------------------------
* STEP 3: Extract Predicted Probabilities for Each Group × Outcome
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 3.1. Probabilities for "Less seats" outcome (first outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 1, stat(est se p) add rowname("Less_C_S23_Other")
* Predicted probability of "less seats" for citizens, 2023 survey, non-VB supporters.

qui mlincom 2, stat(est se p) add rowname("Less_C_S23_Vb")
* Predicted probability of "less seats" for citizens, 2023 survey, VB supporters.

qui mlincom 3, stat(est se p) add rowname("Less_P_S23_Other")
* Predicted probability of "less seats" for politicians, 2023 survey, non-VB supporters.

qui mlincom 4, stat(est se p) add rowname("Less_P_S23_Vb")
* Predicted probability of "less seats" for politicians, 2023 survey, VB supporters.

qui mlincom 5, stat(est se p) add rowname("Less_C_S24_Other")
* Predicted probability of "less seats" for citizens, 2024 survey, non-VB supporters.

qui mlincom 6, stat(est se p) add rowname("Less_C_S24_Vb")
* Predicted probability of "less seats" for citizens, 2024 survey, VB supporters.

qui mlincom 7, stat(est se p) add rowname("Less_P_S24_Other")
* Predicted probability of "less seats" for politicians, 2024 survey, non-VB supporters.

qui mlincom 8, stat(est se p) add rowname("Less_P_S24_Vb")
* Predicted probability of "less seats" for politicians, 2024 survey, VB supporters.

* ------------------------------------------------------------------------------
* 3.2. Probabilities for "Same as now" outcome (second outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 9, stat(est se p) add rowname("Same_C_S23_Other")
* Predicted probability of "same as now" for citizens, 2023 survey, non-VB supporters.

qui mlincom 10, stat(est se p) add rowname("Same_C_S23_Vb")
* Predicted probability of "same as now" for citizens, 2023 survey, VB supporters.

qui mlincom 11, stat(est se p) add rowname("Same_P_S23_Other")
* Predicted probability of "same as now" for politicians, 2023 survey, non-VB supporters.

qui mlincom 12, stat(est se p) add rowname("Same_P_S23_Vb")
* Predicted probability of "same as now" for politicians, 2023 survey, VB supporters.

qui mlincom 13, stat(est se p) add rowname("Same_C_S24_Other")
* Predicted probability of "same as now" for citizens, 2024 survey, non-VB supporters.

qui mlincom 14, stat(est se p) add rowname("Same_C_S24_Vb")
* Predicted probability of "same as now" for citizens, 2024 survey, VB supporters.

qui mlincom 15, stat(est se p) add rowname("Same_P_S24_Other")
* Predicted probability of "same as now" for politicians, 2024 survey, non-VB supporters.

qui mlincom 16, stat(est se p) add rowname("Same_P_S24_Vb")
* Predicted probability of "same as now" for politicians, 2024 survey, VB supporters.

* ------------------------------------------------------------------------------
* 3.3. Probabilities for "More seats" outcome (third outcome category in ologit)
* ------------------------------------------------------------------------------

qui mlincom 17, stat(est se p) add rowname("More_C_S23_Other")
* Predicted probability of "more seats" for citizens, 2023 survey, non-VB supporters.

qui mlincom 18, stat(est se p) add rowname("More_C_S23_Vb")
* Predicted probability of "more seats" for citizens, 2023 survey, VB supporters.

qui mlincom 19, stat(est se p) add rowname("More_P_S23_Other")
* Predicted probability of "more seats" for politicians, 2023 survey, non-VB supporters.

qui mlincom 20, stat(est se p) add rowname("More_P_S23_Vb")
* Predicted probability of "more seats" for politicians, 2023 survey, VB supporters.

qui mlincom 21, stat(est se p) add rowname("More_C_S24_Other")
* Predicted probability of "more seats" for citizens, 2024 survey, non-VB supporters.

qui mlincom 22, stat(est se p) add rowname("More_C_S24_Vb")
* Predicted probability of "more seats" for citizens, 2024 survey, VB supporters.

qui mlincom 23, stat(est se p) add rowname("More_P_S24_Other")
* Predicted probability of "more seats" for politicians, 2024 survey, non-VB supporters.

qui mlincom 24, stat(est se p) add rowname("More_P_S24_Vb")
* Predicted probability of "more seats" for politicians, 2024 survey, VB supporters.

* ------------------------------------------------------------------------------
* STEP 4: Average Marginal Effects (AME) of Preferring VB
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 4.1. AME of preferring VB for "Less seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 2 - 1, stat(est se p) add rowname("Less_AME_Vb_C_S23")
* Difference in predicted probabilities of "less seats" between VB supporters and others
* among citizens in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 6 - 5, stat(est se p) add rowname("Less_AME_Vb_C_S24")
* Difference in predicted probabilities of "less seats" between VB supporters and others
* among citizens in 2024 survey, showing the marginal effect of VB preference.

qui mlincom 4 - 3, stat(est se p) add rowname("Less_AME_Vb_P_S23")
* Difference in predicted probabilities of "less seats" between VB supporters and others
* among politicians in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 8 - 7, stat(est se p) add rowname("Less_AME_Vb_P_S24")
* Difference in predicted probabilities of "less seats" between VB supporters and others
* among politicians in 2024 survey, showing the marginal effect of VB preference.

* ------------------------------------------------------------------------------
* 4.2. AME for "Same as now" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 10 - 9, stat(est se p) add rowname("Same_AME_Vb_C_S23")
* Difference in predicted probabilities of "same as now" between VB supporters and others
* among citizens in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 14 - 13, stat(est se p) add rowname("Same_AME_Vb_C_S24")
* Difference in predicted probabilities of "same as now" between VB supporters and others
* among citizens in 2024 survey, showing the marginal effect of VB preference.

qui mlincom 12 - 11, stat(est se p) add rowname("Same_AME_Vb_P_S23")
* Difference in predicted probabilities of "same as now" between VB supporters and others
* among politicians in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 16 - 15, stat(est se p) add rowname("Same_AME_Vb_P_S24")
* Difference in predicted probabilities of "same as now" between VB supporters and others
* among politicians in 2024 survey, showing the marginal effect of VB preference.

* ------------------------------------------------------------------------------
* 4.3. AME for "More seats" by type and survey:
* ------------------------------------------------------------------------------

qui mlincom 18 - 17, stat(est se p) add rowname("More_AME_Vb_C_S23")
* Difference in predicted probabilities of "more seats" between VB supporters and others
* among citizens in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 22 - 21, stat(est se p) add rowname("More_AME_Vb_C_S24")
* Difference in predicted probabilities of "more seats" between VB supporters and others
* among citizens in 2024 survey, showing the marginal effect of VB preference.

qui mlincom 20 - 19, stat(est se p) add rowname("More_AME_Vb_P_S23")
* Difference in predicted probabilities of "more seats" between VB supporters and others
* among politicians in 2023 survey, showing the marginal effect of VB preference.

qui mlincom 24 - 23, stat(est se p) add rowname("More_AME_Vb_P_S24")
* Difference in predicted probabilities of "more seats" between VB supporters and others
* among politicians in 2024 survey, showing the marginal effect of VB preference.

* ------------------------------------------------------------------------------
* STEP 5: Test 2nd Differences (Difference-in-Differences of AMEs)
* ------------------------------------------------------------------------------

* ------------------------------------------------------------------------------
* 5.1. Difference in AME between citizens and politicians, by survey wave, for "Less seats":
* ------------------------------------------------------------------------------

qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("L_2_Vb_S23")
* Tests whether the difference in the effect of VB preference on "less seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("L_2_Vb_S24")
* Tests whether the difference in the effect of VB preference on "less seats"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.2. Difference in AME between citizens and politicians, by survey wave, for "Same as now":
* ------------------------------------------------------------------------------

qui mlincom (10 - 9) - (12 - 11), stat(est se p) add rowname("S_2_Vb_S23")
* Tests whether the difference in the effect of VB preference on "same as now"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (14 - 13) - (16 - 15), stat(est se p) add rowname("S_2_Vb_S24")
* Tests whether the difference in the effect of VB preference on "same as now"
* between citizens and politicians differs significantly in 2024 survey.

* ------------------------------------------------------------------------------
* 5.3. Difference in AME between citizens and politicians, by survey wave, for "More seats":
* ------------------------------------------------------------------------------

qui mlincom (18 - 17) - (20 - 19), stat(est se p) add rowname("M_2_Vb_S23")
* Tests whether the difference in the effect of VB preference on "more seats"
* between citizens and politicians differs significantly in 2023 survey.

qui mlincom (22 - 21) - (24 - 23), stat(est se p) add rowname("M_2_Vb_S24")
* Tests whether the difference in the effect of VB preference on "more seats"
* between citizens and politicians differs significantly in 2024 survey.

* ---------------------------------------------------------
* STEP 6: Test 3rd Differences (Change over Survey in 2nd Differences)
* ---------------------------------------------------------

* The 3rd difference tests whether the difference-in-differences (2nd differences)
* between citizens and politicians in the effect of VB preference changes from 2023 survey to 2024 survey.

* ------------------------------------------------------------------------------
* 6.1. For "Less seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("Less_3_Vb")
* Tests whether the gap in AMEs between citizens and politicians for "less seats" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.2. For "Same as now" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((14 - 13) - (16 - 15)) - ((10 - 9) - (12 - 11)), stat(est se p) add rowname("Same_3_Vb")
* Tests whether the gap in AMEs between citizens and politicians for "same as now" changes significantly across surveys.

* ------------------------------------------------------------------------------
* 6.3. For "More seats" outcome:
* ------------------------------------------------------------------------------

qui mlincom ((22 - 21) - (24 - 23)) - ((18 - 17) - (20 - 19)), stat(est se p) add rowname("More_3_Vb")
* Tests whether the gap in AMEs between citizens and politicians for "more seats" changes significantly across surveys.

* ---------------------------------------------------------
* STEP 7: Display All Results with Title
* ---------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Vb) and Tests of 2nd and 3rd Differences")


********************************************************************************
** UPDATED: SECOND DIFFERENCES (PVDA) - BINARY DV VERSION
********************************************************************************

* -------------------------------------------------------------------------------
* STEP 1: Binary Logit Model — 3-Way Interaction for PVDA
* -------------------------------------------------------------------------------

logit seats_pvda_correct i.party_pvda##i.type##i.survey i.sex age
* Estimate a binary logit model predicting 'seats_pvda' (e.g., 1 = more seats),
* with a full three-way interaction between party preference, type, and survey.
* Controls include sex and age.

* -------------------------------------------------------------------------------
* STEP 2: Compute Predicted Probabilities for Each Subgroup
* -------------------------------------------------------------------------------

margins, over(party_pvda) at(type=(1 2) survey=(1 2)) post
* Predicted probabilities of 'seats_pvda == 1' (e.g., more seats) for each subgroup.

mlincom, clear
* Clear any previous linear combinations.

* -------------------------------------------------------------------------------
* STEP 3: AMEs (Average Marginal Effects) of Preferring PVDA
* -------------------------------------------------------------------------------

* Citizens, 2023
qui mlincom 2 - 1, stat(est se p) add rowname("AME_Pvda_C_S23")

* Politicians, 2023
qui mlincom 4 - 3, stat(est se p) add rowname("AME_Pvda_P_S23")

* Citizens, 2024
qui mlincom 6 - 5, stat(est se p) add rowname("AME_Pvda_C_S24")

* Politicians, 2024
qui mlincom 8 - 7, stat(est se p) add rowname("AME_Pvda_P_S24")

* -------------------------------------------------------------------------------
* STEP 4: Test 2nd Differences (Difference-in-Differences of AMEs)
* -------------------------------------------------------------------------------

* Survey 2023: Citizens vs. Politicians
qui mlincom (2 - 1) - (4 - 3), stat(est se p) add rowname("2ndDiff_Pvda_S23")

* Survey 2024: Citizens vs. Politicians
qui mlincom (6 - 5) - (8 - 7), stat(est se p) add rowname("2ndDiff_Pvda_S24")

* -------------------------------------------------------------------------------
* STEP 5: Test 3rd Difference (Change over Time in 2nd Differences)
* -------------------------------------------------------------------------------

qui mlincom ((6 - 5) - (8 - 7)) - ((2 - 1) - (4 - 3)), stat(est se p) add rowname("3rdDiff_Pvda")

* -------------------------------------------------------------------------------
* STEP 6: Display All Results
* -------------------------------------------------------------------------------

mlincom, stat(est se p) title("AMEs for Party Preference (Pvda) and Tests of 2nd and 3rd Differences")










ologit seats_pvda i.party_pvda##c.sophistication_index i.sex age

margins, at(sophistication_index=gen(sophistication_index)) at(sophistication_index=gen(sophistication_index + 1)) over(party_pvda) post
mlincom, clear

*Fewer seats
*Effect of +1 on sophistication index for respondents who said they felt close to another party
qui mlincom 3 - 1, stat(est se p) add rowname("AME: L_NonPVDA")
*Effect of +1 on sophistication index for respondents who said they felt close to the PVDA
qui mlincom 4 - 2, stat(est se p) add rowname("AME: L_PVDA")

*Same as now
*Effect of +1 on sophistication index for respondents who said they felt close to another party
qui mlincom 7 - 5, stat(est se p) add rowname("AME: S_NonPVDA")
*Effect of +1 on sophistication index for respondents who said they felt close to the PVDA
qui mlincom 8 - 6, stat(est se p) add rowname("AME: S_PVDA")

*More seats
qui mlincom 11 - 9, stat(est se p) add rowname("AME: M_NonPVDA")
*Effect of +1 on sophistication index for respondents who said they felt close to the PVDA
qui mlincom 12 - 10, stat(est se p) add rowname("AME: M_PVDA")

*Second Difference: Fewer seats
qui mlincom (4 - 2) - (3 - 1), stat(est se p) add rowname("2nd Diff: L_PVDA_NonPVDA")

*Second Difference: Same as now
qui mlincom (8 - 6) - (7 - 5), stat(est se p) add rowname("2nd Diff: S_PVDA_NonPVDA")

*Second Difference: More seats
qui mlincom (12 - 10) - (11 - 9), stat(est se p) add rowname("2nd Diff: M_PVDA_NonPVDA")

mlincom, stat(est se p) title("AMEs and Test of 2nd Difference")
